package com.game.modular.game.battle.process.battleStage.actionPhase.actionPhase2;

import com.game.modular.game.battle.panel.attribute.domain.PlayerHeroAttribute;
import com.game.modular.game.battle.panel.attribute.PlayerHeroAttributeServiceImpl;
import com.game.modular.game.battle.process.battleStage.actionPhase.actionPhase2.item.OrdinaryAttackStrategy;
import com.game.modular.game.battle.process.battleStage.actionPhase.actionPhase2.item.ReleaseSkillService;
import com.game.modular.game.playerAssets.domain.PlayerHero;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 2
 * 武将行动阶段
 */
@Slf4j
@Service
public class ActionService {
    @Resource
    private PlayerHeroAttributeServiceImpl attributeService;
    @Resource
    private ReleaseSkillService releaseSkillService;
    @Resource
    private OrdinaryAttackStrategy ordinaryAttack;

    public void apply(
            Long battleId,
            int roundCount,
            int orderOfAction,
            PlayerHero actWJ,
            List<PlayerHero> targetRange
    ){
        PlayerHeroAttribute attribute = attributeService.get(battleId, actWJ.getId());
        attribute.setPhase(22);
        boolean use = attributeService.statusUseAndRefresh(attribute, 23L);
        if (!use){
            generalAction(battleId, roundCount, orderOfAction, actWJ, targetRange);
        }else {
            log.info("---武将{}({})混乱", actWJ.getName(), actWJ.getId());
        }
    }

    private void generalAction(
            Long battleId, int roundCount, int orderOfAction, PlayerHero actWJ, List<PlayerHero> targetRange
    ) {
        releaseSkillService.heroReleaseSkills(
                battleId, roundCount, orderOfAction, actWJ, 1,targetRange
        );
        ordinaryAttack.apply(
                battleId, roundCount, orderOfAction, actWJ, targetRange
        );
    }
}
